//
//  HNSH_ChatGroupNavView.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/2/17.
//

#import "HNSH_ChatGroupNavView.h"

@interface HNSH_ChatGroupNavView ()
/** 返回按钮 */
@property (nonatomic, strong)UIButton * backBtn;
/**  */
@property (nonatomic, strong)UIButton * centerBtn;
/**  */
@property (nonatomic, strong)UIButton * searchBtn;
@end

@implementation HNSH_ChatGroupNavView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addAllViews];
        [self addAllLayout];
    }
    return self;
}

//MARK: Myself Methods
- (void)addAllViews{
    self.backgroundColor = [UIColor appWhiteLabelColor];
    [self addSubview:self.backBtn];
    [self addSubview:self.centerBtn];
    [self addSubview:self.searchBtn];
}

- (void)addAllLayout{
    [self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.width.mas_equalTo(44);
        make.height.mas_equalTo(44);
        make.top.mas_equalTo(kStatusBarHeight);
    }];
    [self.centerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.backBtn.mas_right);
        make.right.mas_equalTo(-44);
        make.height.mas_equalTo(44);
        make.top.mas_equalTo(kStatusBarHeight);
    }];
    [self.searchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(0);
        make.width.mas_equalTo(44);
        make.height.mas_equalTo(44);
        make.top.mas_equalTo(kStatusBarHeight);
    }];
}

//MARK: Myself Methods
- (void)backBtnAction{
    if (self.backBlock) {
        self.backBlock();
    }
}

- (void)searchBtnAction{
    if (self.reportBlock) {
        self.reportBlock();
    }
}

#pragma mark - Setter Methods
- (void)setTitle:(NSString *)title{
    _title = title;
    
    [self.centerBtn setTitle:title forState:UIControlStateNormal];
}

- (void)setIsHiddenBtn:(BOOL)isHiddenBtn{
    _isHiddenBtn = isHiddenBtn;
    
    self.searchBtn.hidden = isHiddenBtn;
}

- (void)setIsDis:(BOOL)isDis{
    _isDis = isDis;
    
    self.centerBtn.selected = isDis;
}

#pragma mark - Getter Methods
- (UIButton *)backBtn{
    if (!_backBtn) {
        _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_backBtn setImage:[UIImage imageNamed:@"base_nav_back_black"] forState:UIControlStateNormal];
        [_backBtn addTarget:self action:@selector(backBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _backBtn;
}

- (UIButton *)centerBtn{
    if (!_centerBtn) {
        _centerBtn = [UIButton new];
        [_centerBtn setTitleColor:[UIColor appBlack333LabelColor] forState:UIControlStateNormal];
        [_centerBtn setImage:nil forState:UIControlStateNormal];
        [_centerBtn setImage:[UIImage imageNamed:@"message_dis"] forState:UIControlStateSelected];
        _centerBtn.titleLabel.font = [UIFont boldSystemFontOfSize:16];
        _centerBtn.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
    }
    return _centerBtn;
}

- (UIButton *)searchBtn{
    if (!_searchBtn) {
        _searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_searchBtn setImage:[UIImage imageNamed:@"base_nav_more"] forState:UIControlStateNormal];
        [_searchBtn addTarget:self action:@selector(searchBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _searchBtn;
}
@end
